/*获取的兴趣方向的数据处理*/
exports.initInterestData = function(arr){
    var result = [];
    arr.forEach(function (item) {
        if(item.parentId === '0'){
            result.push(item);
        }
    });
    result.forEach(function (parent) {
        arr.forEach(function (item) {
            if (item.parentId === parent.id){
                if (!parent.child){
                    parent.child = [item];
                }else {
                    parent.child.push(item);
                }
                return false;
            }
        })
    });
    return result;
};
/*返回时间戳*/
exports.typeToTimeStamp = function(type) {
    if(!type){
        return '';
    }
    var arr = ["week", "month","quarter","halfyear"];
    var arrTime = [7,32,123,181];
    var index = arr.indexOf(type);
    var current = Date.now();
    var older = current - arrTime[index] * 24 * 60 * 60 *1000;
    return older;
};
exports.toHtml =function (str){
    str = str.replace(/</ig,'&lt;');
    str = str.replace(/>/ig,'&gt;');
    str = str.replace(/\n/ig,'<br />');
    str = str.replace(/\[code\](.+?)\[\/code\]/ig, function($1, $2) {return phpcode($2);});

    str = str.replace(/\[hr\]/ig,'<hr />');
    str = str.replace(/\[\/(size|color|font|backcolor)\]/ig,'</font>');
    str = str.replace(/\[(sub|sup|u|i|strike|b|blockquote|li)\]/ig,'<$1>');
    str = str.replace(/\[\/(sub|sup|u|i|strike|b|blockquote|li)\]/ig,'</$1>');
    str = str.replace(/\[\/align\]/ig,'</p>');
    str = str.replace(/\[(\/)?h([1-6])\]/ig,'<$1h$2>');

    str = str.replace(/\[align=(left|center|right|justify)\]/ig,'<p align="$1">');
    str = str.replace(/\[size=(\d+?)\]/ig,'<font size="$1">');
    str = str.replace(/\[color=([^\[\<]+?)\]/ig, '<font color="$1">');
    str = str.replace(/\[backcolor=([^\[\<]+?)\]/ig, '<font style="background-color:$1">');
    str = str.replace(/\[font=([^\[\<]+?)\]/ig, '<font face="$1">');
    str = str.replace(/\[list=(a|A|1)\](.+?)\[\/list\]/ig,'<ol type="$1">$2</ol>');
    str = str.replace(/\[(\/)?list\]/ig,'<$1ul>');

    str = str.replace(/\[s:(\d+)\]/ig,function($1,$2){ return smilepath($2);});
    str = str.replace(/\[img\]([^\[]*)\[\/img\]/ig,'<img src="$1" border="0" />');
    str = str.replace(/\[url=([^\]]+)\]([^\[]+)\[\/url\]/ig, '<a href="$1">'+'$2'+'</a>');
    str = str.replace(/\[url\]([^\[]+)\[\/url\]/ig, '<a href="$1">'+'$1'+'</a>');
    str = str.replace(/\[p\]/ig,'');
    str = str.replace(/\[\/p\]/ig,'</br>');
    return str;
}